﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;
using E2_WEBSITE.Code.Admin;
using E2_WEBSITE.Code;

namespace E2_WEBSITE.cp.admin.user
{
    public partial class changepass : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnAccept_Click(object sender, EventArgs e)
        {
            if (Session["UserID"] == null)
            {
                WebMsgBox.Show("Hãy đăng nhập để sử dụng chức năng này.");
                return;
            }
            try
            {
                UserController controller = new UserController();
                string hashedOldPassword = FormsAuthentication.HashPasswordForStoringInConfigFile(tbOldPassword.Text, "sha1");
                string hashedNewPassword = FormsAuthentication.HashPasswordForStoringInConfigFile(tbNewPassword.Text, "sha1");
                if (controller.ChangePassword(Convert.ToInt32(Session["UserID"]), hashedOldPassword, hashedNewPassword))
                {
                    WebMsgBox.Show("Cập nhật mật khẩu thành công.");
                }
            }
            catch (Exception)
            {
                Response.Redirect(Utilities.ErrorPagePath);
                throw;
            }
        }
    }
}
